<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .father {
            /* position: relative; */
            width: 200px;
            height: 180px;
            background-color: pink;
            border: 2px solid red;
            padding: 5px;
            margin: 150px;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: purple;
            margin-left: 45px;
        }

        .w {
            /* width: 300px; */
            height: 200px;
            background-color: skyblue;
            margin: 0 auto 200px;
            padding: 10px;
            border: 15px solid red;
        }
    </style>
</head>
<body>
    <div class="father">father
      <div class="son">son</div>
    </div>
    <div class="w"></div>
    <script>
        /*
          offset
             offsetLeft：元素左侧的偏移量，    返回值是数值型
             offsetTOP：元素顶部的偏移量，     返回值是数值型
             offsetLeft 和 offsetTOP 是以父级为参照物。父级必须有定位，否则是baby的距离。
             没有右侧和底部的偏移量

             offsetWidth/offsetHeight 元素的动态宽度  width + border + padding
             offsetParent 获取有定位的父级元素
        */
       var father = document.querySelector('.fether');
       var son = document.querySelector('.son');
       console.log(typeof father.offsetLeft);
       console.log(father.offsetTop);
       console.log(son.offsetLeft);
       console.log('-------------------------------');
       console.log(father.offsetWidth);
       console.log(father.offsetHeight);
       console.log('*********************************');
       console.log(son.offsetParent);
       console.log(son.parentNode);
       console.log('------------------------------');
       var w = document.querySelector('.w');
       console.log(w.offsetWidth);
    </script>
</body>
</html>